package com.tanhua.api.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.User;
import com.tanhua.mapper.UserMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    // 保存用户insert
    public long saveUser(User user) {
        userMapper.insert(user); //执行完毕 该user就已经有数据库生成的id了
        return user.getId();  //主键返回策略： 将保存对象生成的id进行返回
    }

    // 根据手机号做查询
    public User findByPhone(String phone) {

        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("phone",phone);
        User user = userMapper.selectOne(qw);
        return user;
    }
}
